package com.wlyuan.index.infrastructure.converter;

import com.wlyuan.core.marker.NamedUtils;
import com.wlyuan.core.marker.ValueUtils;
import com.wlyuan.index.domain.index.CombineIndex;
import com.wlyuan.index.domain.index.valueobj.CombineRelation;
import com.wlyuan.index.domain.source.Combine;
import com.wlyuan.index.domain.source.utils.SourceUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;

public class CombineIndexConverter {
    @Mapper(uses = {ValueUtils.class, NamedUtils.class, SourceUtils.class},
            imports = {LocalDateTime.class})
    public interface Converter {
        @Mapping(target = "customerId", source = "customer.customerId")
        @Mapping(target = "customerName", source = "customer.name")
        @Mapping(target = "customerType", source = "customer.type")
        @Mapping(target = "carrierId", source = "carrier.carrierId")
        @Mapping(target = "carrierName", source = "carrier.name")
        @Mapping(target = "carrierType", source = "carrier.type")
        @Mapping(target = "closeType", source = "close.type")
        @Mapping(target = "closeStatus", source = "close.status")
        @Mapping(target = ".", source = "statistics")
        @Mapping(target = "indexAt", expression = "java(LocalDateTime.now())")
        CombineIndex convert(Combine source);

        @Mapping(target = "callQuote", source = "canQuote")
        CombineRelation convertRelation(com.wlyuan.index.domain.source.valueobj.CombineRelation source);
    }

    private static final Converter CONVERTER = Mappers.getMapper(Converter.class);

    public static CombineIndex convert(Combine source) {
        return CONVERTER.convert(source);
    }
}
